<?php
include('../../__global.php');
//单品最终页下面的转采
class aj_goodsComment extends ml_controller {

    private $uid;
    private $page=1;                                    //默认第0页
    private $begin=0;
    private $rid;

    function initParam() {

        $this->rid   = $this->input('rid');
        $tmp=intval($this->input('page','G'));
        $this->page = empty($tmp)?$this->page:$tmp;//页
        $this->begin =($this->page-1)*4;//每页4个评论

    }

    function checkParam() {

        $this->check_referer();
        if (!ml_tool_resid::is_resid($this->rid)) {
            $this->api_output(ML_RCODE_PARAM,'','wrong rid');
        }


    }

    public function main() {

        $re_model=new ml_model_dbCollectionComment();
        $data=$re_model->getComment($this->rid, $this->begin,'4');
        $total=$re_model->getTotal($this->rid);

        $uids=array();
        foreach ($data as &$value) {
            $uids[]=$value['uid'];
            $value['time'] = ml_tool_standardShow::time($value['ctime']);

            
            $value['comment'] = ml_tool_formatContent::format_content($value['comment']);
            $value['headPic']= ml_tool_picid::uid2portrait($value['uid'] , 'tny');

        }
        if(!empty($uids)){
            $aNicks = ml_tool_nick::uids2nicks($uids);

            foreach ($data as &$v_nick) {
                $v_nick['nick'] = $aNicks[$v_nick['uid']];
            }
        }
        $final['totalNum']=$total['num'];
        $final['items']=$data;
        $this->api_output(ML_RCODE_SUCC,$final);

    }


}

new aj_goodsComment();